﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace MyLibrary
{
    /// <summary>
    /// 调试信息输出类
    /// </summary>
    public static class Debuger
    {
        static Mutex sync = new Mutex();

        public static void PrintDebugMessage(string message)
        {
            sync.WaitOne();
            ConsoleColor oldColor = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Magenta;

            Trace.WriteLine(String.Format("(0x{1:X8}){0}", message, Thread.CurrentThread.ManagedThreadId));
            Console.ForegroundColor = oldColor;
            sync.ReleaseMutex();
        }

        public static void PrintErrorMessage(string message)
        {
            sync.WaitOne();

            ConsoleColor oldColor = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Red;

            Trace.WriteLine(String.Format("(0x{2:X8}){0}", message, Thread.CurrentThread.ManagedThreadId));
            Console.ForegroundColor = oldColor;
            sync.ReleaseMutex();
        }
    }
}
